package com.ruoyi.project.system.recycler.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.recycler.domain.Recycler;
import com.ruoyi.project.system.recycler.service.IRecyclerService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 回收员管理Controller
 * 
 * @author ruoyi
 * @date 2025-01-06
 */
@Controller
@RequestMapping("/system/recycler")
public class RecyclerController extends BaseController
{
    private String prefix = "system/recycler";

    @Autowired
    private IRecyclerService recyclerService;

    @RequiresPermissions("system:recycler:view")
    @GetMapping()
    public String recycler()
    {
        return prefix + "/recycler";
    }

    /**
     * 查询回收员管理列表
     */
    @RequiresPermissions("system:recycler:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Recycler recycler)
    {
        startPage();
        List<Recycler> list = recyclerService.selectRecyclerList(recycler);
        return getDataTable(list);
    }

    /**
     * 导出回收员管理列表
     */
    @RequiresPermissions("system:recycler:export")
    @Log(title = "回收员管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Recycler recycler)
    {
        List<Recycler> list = recyclerService.selectRecyclerList(recycler);
        ExcelUtil<Recycler> util = new ExcelUtil<Recycler>(Recycler.class);
        return util.exportExcel(list, "回收员管理数据");
    }

    /**
     * 新增回收员管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存回收员管理
     */
    @RequiresPermissions("system:recycler:add")
    @Log(title = "回收员管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Recycler recycler)
    {
        return toAjax(recyclerService.insertRecycler(recycler));
    }

    /**
     * 修改回收员管理
     */
    @RequiresPermissions("system:recycler:edit")
    @GetMapping("/edit/{recyclerId}")
    public String edit(@PathVariable("recyclerId") Long recyclerId, ModelMap mmap)
    {
        Recycler recycler = recyclerService.selectRecyclerByRecyclerId(recyclerId);
        mmap.put("recycler", recycler);
        return prefix + "/edit";
    }

    /**
     * 修改保存回收员管理
     */
    @RequiresPermissions("system:recycler:edit")
    @Log(title = "回收员管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Recycler recycler)
    {
        return toAjax(recyclerService.updateRecycler(recycler));
    }

    /**
     * 删除回收员管理
     */
    @RequiresPermissions("system:recycler:remove")
    @Log(title = "回收员管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(recyclerService.deleteRecyclerByRecyclerIds(ids));
    }
}
